﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace redisdemo
{
    using System.Threading;

    using StackExchange.Redis;

    class Program
    {

        static ConnectionMultiplexer redisClient = ConnectionMultiplexer.Connect("localhost");
        static void Main(string[] args)
        {
            IDatabase db = redisClient.GetDatabase();
            // 测试 key value
            string value = "abcdefg";
            db.StringSet("mykey", value);
             value = db.StringGet("mykey");
            Console.WriteLine(value);
            // 测试消息队列
            ISubscriber sub = redisClient.GetSubscriber();
            sub.Subscribe("messages", (channel, message) => {
                Console.WriteLine((string)message);
            });
            Thread.Sleep(1000);
            sub.Publish("messages", "hello");

            Thread.Sleep(1000);
            sub.Publish("redisMessages", "This message from C# program");

            Console.ReadKey();
        }
    }
}
